package org.abacus.hibernate;

/**
 * @author chaoyang.li
 */
public class HibernateSessionFilter implements SessionFilter {
	private static final ThreadLocal<SessionFilter> instance = new ThreadLocal<SessionFilter>();

	protected HibernateSessionFilter() {
		super();
	}

	/**
	 * @author chaoyang.li
	 */
	public static SessionFilter getInstance() {
		if (instance.get() == null) {
			instance.set(new HibernateSessionFilter());
		}
		return instance.get();
	}

	/**
	 * @author chaoyang.li
	 */
	public void open() {
		for (String tag : HibernateSessionProvider.getTags()) {
			open(tag);
		}
	}

	/**
	 * @author chaoyang.li
	 */
	public void close() {
		for (String tag : HibernateSessionProvider.getTags()) {
			close(tag);
		}
	}

	/**
	 * @author chaoyang.li
	 * @param tag
	 */
	public void open(String tag) {
		HibernateSessionProvider.getCurrentSession(tag);
	}

	/**
	 * @author chaoyang.li
	 * @param tag
	 */
	public void close(String tag) {
		HibernateSessionProvider.close(tag);
	}
}
